/*
 * @Author: viivLgr 
 * @Date: 2018-03-20 22:59:12 
 * @Last Modified by: viivLgr
 * @Last Modified time: 2018-03-20 23:33:13
 */

'use strict';

require('./index.css');
var _util = require('util/util.js');

// 通用页面头部
var header = {
    init: function () {
        this.onLoad();
        this.bindEvent();
    },
    onLoad: function () {
        var keyword = _util.getUrlParam('keyword');
        if (keyword) {
            // 若keyword存在，则回填输入框
            $('#search-input').val(keyword);
        }
    },
    bindEvent: function () {
        var _this = this;
        // 点击搜索按钮后提交
        $('#search-btn').click(function () {
            _this.searchSubmit();
        });
        // 输入回车后，搜索提交
        $('#search-input').keyup(function(e){
            if(e.keyCode === 13){
                // 13是回车键
                _this.searchSubmit();
            }
        });
    },
    // 搜索的提交
    searchSubmit: function () {
        var keyword = $.trim($('#search-input').val());
        if(keyword){
            window.location.href = './list.html?keyword=' + keyword;
        }else{
            _util.goHome();
        }
    }
};
header.init();